Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility to prune unused go library targets #6149

Merged
merged 1 commit into from
Jan 8, 2018

Conversation

fejta
Copy link
Contributor

@fejta fejta commented Jan 4, 2018

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 4, 2018
@chrislovecnm
Copy link
Contributor

I know you are trying to reduce the files in vendor folder, and I like that. A challenge is when you add a new library and are not using the library, but will use it in other PRs that are inbound. I would rather not vendor a dependency, and add code for that dependency in the same PR, as the PR review can be nutty. What is the workflow that is used in this repo? Are we going to run into the same problem I just ran into with the aws vendoring? I like reducing the number of files, but not sure how we cannot step on our own toes.

@cjwagner
Copy link
Member

cjwagner commented Jan 8, 2018

@chrislovecnm Typically we include the dependencies in the same PR, but add them in a separate commit so that reviewers can filter changes to the interesting commits with the Github review UI.

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of scoping statement masking and quoting nits, maybe a run through ShellCheck would help? Content LGTM


# Output the target if it has only one dependency (itself)
is-unused() {
local n="$(bazel query "rdeps(//..., \"$1\", 1)" | wc -l)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mix scoping and evaluation or scoping will overwrite the return code of evaluation:

local n
n=$(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


# Convert //foo/bar:stuff to //foo/bar
package-name() {
echo $1 | cut -d : -f 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably a potential word-splitting bug here without quotes around $1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

# Output foo/bar/whatever.sh
local base=$(basename $i)
local dir=$(dirname $i)
echo ${dir:2}/$(echo $base | sed -e 's|:|/|1')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you feel about this but could get rid of two exec calls by using the shell built-in string replace instead of echo | sed

echo "${dir:2}/${base/:/\/}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jan 8, 2018
Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold


script="$(dirname ${BASH_SOURCE})/prune-libraries.sh" --check
if ! "$script" ; then
echo "Run $script -- fix"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/-- fix/--fix/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cjwagner, fejta

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@fejta
Copy link
Contributor Author

fejta commented Jan 8, 2018

@chrislovecnm let's commit new vendored deps when they are used, as cjwagner describes (what we have been doing).

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 8, 2018
@k8s-ci-robot k8s-ci-robot merged commit 5349694 into kubernetes:master Jan 8, 2018
@fejta fejta deleted the fix branch January 8, 2018 19:45
@ixdy
Copy link
Member

ixdy commented Jan 9, 2018

How do we get hack/verify-vendor.sh running in CI? It seems like it's likely to break otherwise.

@0xmichalis
Copy link
Contributor

0xmichalis commented Jan 9, 2018

This seems to work around dep which was recently added in test-infra for dep management. Did you evaluate dep prune? See here for an example where dep files get stale.

@BenTheElder
Copy link
Member

dep prune needs work golang/dep#944

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants